# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import torch

import VoxDataset
import train
import logging
import visualization
import IOU

def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.

def mytrain(num):
    print(torch.cuda.is_available())
    path = '模型/模型/1/' + num.__str__() + '.binvox'
    trainer = train.Train(path)
    trainer.training()
    print('training done')
    savingpath = 'model/' + num.__str__() + '(final,48).pth'
    trainer.saving(savingpath)
    print('saving done')

def loadAndRebuild(num):
    loaingpath = 'model/' + num.__str__() + '(final,48).pth'
    path = '模型/模型/1/' + num.__str__() + '.binvox'
    trainer = train.Train(path)
    trainer.loaing(loaingpath)
    trainer.export(num)
    print(num.__str__() + 'done')

def IOUcount(num):
    originpath = '模型/模型/1/' + num.__str__() + '.binvox'
    rebuildpath = '模型/output/' + num.__str__() + '(final,48).binvox'
    IOUtester = IOU.IOUtester(originpath, rebuildpath)
    U, I = IOUtester.calculate()
    print(U)
    print(I)
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    #TODO 模型归一化
    #TODO 去掉输出层，直接用原有的16个节点累加做反向传播？
    #TODO 权重性采样
    #TODO 误差可视化
    num = 5
    # torch.cuda.empty_cache()
    # #调用训练接口，生成神经网络
    # mytrain(num)
    # torch.cuda.empty_cache()
    # #调用重建接口，输出binvox文件
    # loadAndRebuild(num)
    # torch.cuda.empty_cache()
    # #计算误差
    # IOUcount(num)
    # torch.cuda.empty_cache()
    for num in range(6):
        visual = visualization.Visualization('模型/模型/1/' + num.__str__() + '.binvox',
                                             '模型/output/' + num.__str__() + '(final,48).binvox',
                                             num)
        visual.outputPC()
    print('end')

# See PyCharm help at https://www.jetbrains.com/help/pycharm/
